home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 July / EnigmA AMIGA RUN 20 (1997)(G.R. Edizioni)(IT)[!][issue 1997-07 & 08][EAR-CD IV].iso / lightwave / arexx_macros / bezier.lwm < prev    next >
Text File  |  1996-12-09  |  2KB  |  115 lines

  1. /* Bezier curve creator
  2.  * Use selected control points to create a bezier curve.
  3.  * By Monte Ohrt © 1994 The Rendering Plant Inc. */
  4.  
  5.  
  6. Version = 1.0
  7. address "LWModelerARexx.port"
  8. libadd = addlib("LWModelerARexx.port",0)
  9. MATHLIB="rexxmathlib.library"
  10. IF POS(MATHLIB , SHOW('L')) = 0 THEN
  11.   IF ~ADDLIB(MATHLIB , 0 , -30 , 0) THEN DO
  12.      call notify(1,"!Can't find "MATHLIB)
  13.         exit
  14.         END
  15.  
  16. sysnam = 'Bezier Curves'
  17. signal on error
  18. signal on syntax
  19.  
  20. call sel_mode(USER)
  21. call req_begin sysnam
  22.  
  23. id_txt = req_addcontrol("Create Bezier",'T',"Curves")
  24. id_txt2 = req_addcontrol("By Monte Ohrt",'T',"")
  25. id_seg = req_addcontrol("Number of Points to make",'n')
  26. id_cur = req_addcontrol("Make a Curve?",'B')
  27. id_cntl = req_addcontrol("Keep original control points?",'B')
  28. call req_setval id_seg, 15
  29. call req_setval id_cur, 1
  30. call req_setval id_cntl, 0
  31. if (~req_post()) then do
  32.     call req_end
  33.     exit
  34. end
  35. curve = ""
  36. segs = req_getval(id_seg)
  37. cur = req_getval(id_cur)
  38. cntl = req_getval(id_cntl)
  39. call req_end()
  40. n = xfrm_begin()
  41. if n=0 then do
  42.   call notify(1,"no points selected!")
  43.   exit
  44.   end
  45. say n
  46. do i = 1 to n
  47.   Point.i= xfrm_getpos(i)
  48.   say Point.i
  49.   end
  50. call xfrm_end()
  51. if (~cntl) then do
  52.    call CUT()
  53.    end
  54. delta = 1.0/segs
  55. parse value point.1 with x y z
  56.  
  57.  
  58. call ADD_BEGIN()
  59.  
  60. curve = curve add_point(x y z)
  61.  
  62. call meter_begin (segs-1), "Creating Bezier Curve"
  63. do i = 1 to (segs-1)
  64.    t=i*delta 
  65.    temp2=1
  66.    do z=1 to (n-1)
  67.    temp2=temp2*(1-t)
  68.    end
  69.    temp3=1
  70.    parse value point.1 with x y z .
  71.    sum=temp2*x
  72.    sum2=temp2*y
  73.    sum3=temp2*z
  74.    do k = 1 to (n-1)
  75.       temp2=temp2*(n-k)*t
  76.       temp3=temp3*k*(1-t)
  77.       temp=temp2/temp3
  78.       j=k+1
  79.       parse value point.j with x y z .
  80.       sum=sum+temp*x
  81.       sum2=sum2+temp*y
  82.       sum3=sum3+temp*z
  83.    end
  84.   curve = curve add_point(sum sum2 sum3) 
  85.   call meter_step
  86. end
  87.  
  88. parse value point.n with x y z
  89.  
  90. curve = curve add_point(x y z)
  91.  
  92. call meter_end
  93.  
  94. if (cur) then do
  95.    call ADD_CURVE curve
  96.    end
  97. call ADD_END
  98.  
  99. if (libadd) then call remlib("LWModelerARexx.port")
  100. exit
  101.  
  102.  
  103.  
  104.  
  105. syntax:
  106. error:
  107.   call end_all
  108.    t=Notify(1,'!Rexx Script Error','@'ErrorText(rc),'Line 'SIGL)
  109.    exit
  110.  
  111. PointCount: PROCEDURE
  112.   n=XFRM_BEGIN()
  113.   call END_ALL()
  114.   return n
  115.